package com.example.bnuzzu.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author Corn
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill....");
        this.strictInsertFill(metaObject,"regtime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"updatetime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"datecreated", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"dateupdated", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"storetime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"modtime", LocalDateTime.class,LocalDateTime.now());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill...");
        this.strictUpdateFill(metaObject,"modtime",LocalDateTime.class,LocalDateTime.now());
        this.strictUpdateFill(metaObject,"dateupdated",LocalDateTime.class,LocalDateTime.now());
        this.strictUpdateFill(metaObject,"updatetime",LocalDateTime.class,LocalDateTime.now());
    }
}
